package monopolyRedux;


public class game {
        public static final String[] property_name = new String[] { "Go",
                "Mediterranean Avenue", "Community Chest", "Baltic Avenue",
                "Income Tax", "Reading Railroad", "Oriental Avenue", "Chance",
                "Vermont Avenue", "Connecticut Avenue", "In Jail/Just Visiting",
                "St. Charles Place", "Electric Company", "States Avenue",
                "Virginia Avenue", "Pennsylvania Railroad", "St. James Place",
                "Community Chest", "Tennessee Avenue", "New York Avenue",
                "Free Parking", "Kentucky Avenue", "Chance", "Indiana Avenue",
                "Illinois Avenue", "B&O Railroad", "Atlantic Avenue",
                "Ventnor Avenue", "Water Works", "Marvin Gardens", "Go To Jail",
                "Pacific Avenue", "North Carolina Avenue", "Community Chest",
                "Pennsylvania Avenue", "Short Line", "Chance", "Park Place",
                "Luxury Tax", "Boardwalk" };
        public static int property_price[] = new int[] { 0, 60, 0, 60, 200, 200,
                100, 0, 100, 120, 0, 140, 150, 140, 160, 200, 180, 0, 180, 200, 0,
                220, 0, 220, 240, 200, 260, 260, 150, 280, 0, 300, 300, 0, 320,
                200, 0, 350, 0, 400 };
        public static int property_rent[] = new int[] { 0, 2, 0, 4, 0, 0, 6, 0, 6,
                8, 0, 10, 0, 10, 12, 0, 14, 0, 14, 16, 0, 18, 0, 18, 20, 0, 22, 22,
                0, 22, 0, 26, 26, 0, 28, 0, 0, 35, 0, 40 };
        public static int property_type[] = new int[] { 
                10, -1, 11, -1, 12, -1, -1, 13, -1, -1,
                14, -1, -1, -1, -1, -1, -1, 11, -1, -1,
                15, -1, 13, -1, -1, -1, -1, -1, -1, -1,
                16,     -1, -1, 11, -1, -1, 13, -1, 16, -1 };
        //-1 - property is not owned
        //Go = 10
        //Community Chest = 11
        //Income Tax = 12
        //Chance = 13
        //In Jail/Just Visiting = 14
        //Free Parking 15
        //Luxury Tax 16
        private String[] playerNames;
        private int numberOfHumanPlayers;
        player[] playerArray;
        
        /**
         * Used for testing purposes
         * @param args
         */
        public static void main(String[] args){
                game Game = new game();
        }
        
        /**
         * Makes getting random numbers easier
         * @param numberOfOptions               Number of possible numbers
         * @return a random integer number from 1 to the number given
         */
        public static int rollDice(int numberOfOptions) {
                return (int) (Math.random() * numberOfOptions) + 1;
        }
        
        /**
         * Default constructor
         */
        game(){
                System.out.println("There is one human player named Mark and one computer player");
                playerNames = new String[2];
                playerNames[0] = "Mark";
                playerNames[1] = "Computer Player";
                numberOfHumanPlayers = 1;
                initGame();
        }
        
        /**
         * Constructor that starter calls
         * @param humanPlayers          number of human players
         * @param playerNamesIn         all of the player's names
         */
        game(int humanPlayers, String[] playerNamesIn){
                playerNames = playerNamesIn;
                numberOfHumanPlayers = humanPlayers;
                initGame();
        }
        
        /**
         * Creates all of the things necessary for the game
         */
        private void initGame(){
                playerArray = new player[playerNames.length];
                for(int count = 0; count < playerNames.length; count++){
                        if(count < numberOfHumanPlayers){
                                humanPlayer Player = new humanPlayer(playerNames[count]);
                                playerArray[count] = Player;
                        }else{
                                computerPlayer Player = new computerPlayer(playerNames[count]);
                                playerArray[count] = Player;
                        }
                }
                runGame();
        }
        
        /**
         * What actually runs the game
         */
        private void runGame() {
                 for(int count = 0; count < playerNames.length; count++){
                         playerArray[count].startTurn();
                 }
        }
        
        /**
         * The class that does the things
         * @author Mark Wiggans
         */
        class player{
                protected boolean isHuman;
                protected String name;
                protected int money = 1500;
                protected int doubles;
                protected positionHandler position;
                
                /**
                 * Called whenever their turn starts
                 */
                public void  startTurn(){
                        System.out.println("It is now "+name+"'s turn");
                        int diceOne = rollDice(6);
                        int diceTwo = rollDice(6);
                        if(diceOne == diceTwo){
                                doubles++;
                        }else{
                                doubles = 0;
                        }
                        if(doubles < 2){
                                position.move(diceOne+diceTwo);
                                
                        }else{
                                
                        }
                }
                
                /**
                 * Creates the position handler
                 */
                void initPlayer(){
                        position = new positionHandler();
                }
        }
        
        /**
         * Stub Classes to differentiate between humans and computers
         * @author Mark Wiggans
         */
        class humanPlayer extends player{
                public humanPlayer(String string) {
                        name = string;
                        initPlayer();
                        isHuman = true;
                }
        }
        class computerPlayer extends player{
                public computerPlayer(String string) {
                        name = string;
                        initPlayer();
                        isHuman = false;
                }       
        }
        
        /**
         * Handles the position of the players on the board
         * @author Mark Wiggans
         */
        class positionHandler{
                int position;
                positionHandler(){
                        position = 0;
                }
                positionHandler(int initPos){
                        position = initPos;
                }
                void move(int changeInPosition){
                        position = position + changeInPosition;
                        if(position > 39){
                                position = position - 40;
                        }
                }
                int getPosition(){
                        return position;
                }
        }
}